//
//  SWTabBar.swift
//  MYSwiftWeiBo
//
//  Created by shingwai chan on 16/2/26.
//  Copyright © 2016年 ChanShingWai. All rights reserved.
//

import UIKit

//设置代理
@objc protocol SWTabBarDelegate: NSObjectProtocol {
    optional
    func mainTabBarCompersBtnClick()
}

class SWTabBar: UITabBar {

    //代理属性 回调点击事件
    weak var mainTabBarDelegate:SWTabBarDelegate?
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width = frame.width / 5
        //设置加号按钮frmae
        compesButton.frame = CGRect(x: 0, y: 0, width: width + 5, height: frame.height)
        compesButton.center = CGPoint(x: frame.width * 0.5 , y: frame.height * 0.5)
        
        
        
    }
    
    //MARK: -- 加号按钮懒加载
    lazy var compesButton: UIButton = {
    
        let button  = UIButton()
        
        //设置图片
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        
        button.addTarget(self, action: "buttonDidClick", forControlEvents: UIControlEvents.TouchUpInside)
    
        return button
    }()
    
    //按钮点击事件
    func buttonDidClick() {
        //事件回调代理方法
        mainTabBarDelegate?.mainTabBarCompersBtnClick?()
    }
    
    
}
